package cn.bone.base.auth;

import cn.bone.base.exception.NoTokenException;
import lombok.Data;

import java.io.Serializable;

@Data
public class JWTInfo implements Serializable{
    private Integer userId;     //用户id
    private Integer userType;   //用户类型
    private Long loginTime;     //用户登录时间
    private String origin;      //用户登录来源(设备)

    private static ThreadLocal<JWTInfo> myInfo = new ThreadLocal<>();

    public static void set(JWTInfo info){
        myInfo.set(info);
    }

    public static JWTInfo get(){
        JWTInfo jwtInfo = myInfo.get();
        if(jwtInfo==null){
            throw new NoTokenException();
        }
        return jwtInfo;
    }

    public static void remove(){
        myInfo.remove();
    }
}
